//
//  DSSHMeRepairsDetailVC.m
//  DSSH
//
//  Created by lcy on 16/4/1.
//  Copyright © 2016年 lcy. All rights reserved.
//

#import "DSSHMeRepairsDetailVC.h"
#import "DSSHMeRepairsDeatailCell.h"
#import "UIView+Round.h"
@interface DSSHMeRepairsDetailVC ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)UITableView*detailTableView;
@end

@implementation DSSHMeRepairsDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupViewAndData];
    [self setupConstraints];
    // Do any additional setup after loading the view.
}
-(void)setupViewAndData
{
    self.title = @"维修详情";
    self.extendedLayoutIncludesOpaqueBars = NO;
    self.edgesForExtendedLayout = UIRectEdgeBottom | UIRectEdgeLeft | UIRectEdgeRight;
    UIBarButtonItem * backBarBtn = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"fanhui"] style:UIBarButtonItemStylePlain target:self action:@selector(backBarBtnClick)];
    self.navigationItem.leftBarButtonItem = backBarBtn;
    //添加右侧的历史记录按钮
    UIBarButtonItem * rightBtn = [[UIBarButtonItem alloc]initWithTitle:@"未维修" style:UIBarButtonItemStylePlain target:self action:nil];
    self.navigationItem.rightBarButtonItem = rightBtn;
    
    self.detailTableView = [[UITableView alloc]init];
    self.detailTableView.delegate = self;
    self.detailTableView.dataSource = self;
    self.detailTableView.layer.borderWidth = 1;
    self.detailTableView.layer.borderColor = [[UIColor grayColor]CGColor];
    [self.detailTableView getRoundView:5];
    [self.view addSubview:self.detailTableView];
}
-(void)setupConstraints
{
    [self.detailTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view).with.offset(5*WIDTH_SCALE);
        make.right.equalTo(self.view).with.offset(-5*WIDTH_SCALE);
        make.top.equalTo(self.view.mas_top).with.offset(5*HIGHT_SCALE);
        make.bottom.equalTo(self.view.mas_bottom).with.offset(-5*HIGHT_SCALE);
    }];
}
-(void)backBarBtnClick
{
    [self.navigationController popViewControllerAnimated:YES];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 4;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0)
    {
        return 4;
    }
    if (section == 1)
    {
        return 2;
    }
    if (section == 3)
    {
        return 1;
    }else
    {
        return 3;
    }
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section != 3)
    {
        NSMutableArray * array1 = [[NSMutableArray alloc]initWithObjects:@"项目名称：",@"项目地址：",@"项目编号：",@"点位路径：", nil];
        NSMutableArray * array2 = [[NSMutableArray alloc]initWithObjects:@"报修人：",@"报修时间：", nil];
         NSMutableArray * array3 = [[NSMutableArray alloc]initWithObjects:@"报修类型：",@"损坏程度：",@"情况说明：", nil];
        NSMutableArray * imageArray1 = [[NSMutableArray alloc]initWithObjects:@"iconfontrenwu",@"iconfont_dizhi",@"gerenxinxi-0",@"ditu1", nil];
        NSMutableArray * imageArray2 = [[NSMutableArray alloc]initWithObjects:@"wode",@"shijian", nil];
        NSMutableArray * imageArray3 = [[NSMutableArray alloc]initWithObjects:@"baoxiuchaxun",@"",@"", nil];
        
        NSMutableArray * tableTitleArray = [[NSMutableArray alloc]initWithObjects:array1,array2,array3, nil];
        NSMutableArray * tableImageArry = [[NSMutableArray alloc]initWithObjects:imageArray1,imageArray2,imageArray3, nil];
        
        DSSHMeRepairsDeatailCell * cell = [tableView cellForRowAtIndexPath:indexPath];
        if (!cell)
        {
            cell = [[NSBundle mainBundle]loadNibNamed:@"DSSHMeRepairsDeatailCell" owner:nil options:nil][0];
        }
        cell.headImage.image = [UIImage imageNamed:tableImageArry[indexPath.section][indexPath.row]];
        cell.titleLabel.text = tableTitleArray[indexPath.section][indexPath.row];
        return cell;
    }else
    {
        NSString * cellID = @"cellID";
        UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];
        if (!cell)
        {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        }
        UIImageView * detailImageView = [[UIImageView alloc]init];
        detailImageView.image = [UIImage imageNamed:@"001"];
        [cell.contentView addSubview:detailImageView];
        float imageViewWidth = ZYAppWidth-44*WIDTH_SCALE-30*WIDTH_SCALE;
        NSLog(@"--%f",imageViewWidth*0.089);
        detailImageView.frame = CGRectMake(44*WIDTH_SCALE, 10*HIGHT_SCALE, imageViewWidth, imageViewWidth*0.45);
        return cell;
    }
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    float imageViewWidth = ZYAppWidth-44*WIDTH_SCALE-30*WIDTH_SCALE;
    if (indexPath.section == 3 )
    {
        return imageViewWidth*0.45+30*HIGHT_SCALE;
    }else
    {
        return 44;
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
